package jnpf.util;


import jnpf.file.FileUploadApi;
import jnpf.provider.file.FileUploadProvider;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class FileUploadUtil {

//    @DubboReference
//    private FileUploadProvider fileUploadProvider;

    @Autowired
    private FileUploadApi fileUploadApi;

    @Value("${file-upload-token:Default c634602a-e1eb-493c-891e-e20bf56b17ac}")
    private String fileUploadToken;

    public byte[] getInputStream(String fileId) {
        // byte[] bytes = fileUploadProvider.getInputStream(fileUploadToken, fileId, "annex");
        byte[] bytes = fileUploadApi.getInputStream(fileId, "annex");
        return bytes;
    }

    public boolean uploadFile(MultipartFile file, String fileName) {
        return fileUploadApi.uploadFile(file, "annex", fileName);
    }
}
